<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>修改试题</title>
<%@include file="../core/head.jsp"%>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" href="${ctx }/css/core.css" type="text/css"></link>
<link rel="stylesheet" href="${ctx }/css/exam.css" type="text/css"></link>
<link rel="stylesheet" href="${ctx }/css/buttons.css" type="text/css"></link>
<script type="text/javascript" src="${ctx }/js/modules/exam/exam.js"></script>
<script type="text/javascript" src="${ctx}/js/modules/code/AjaxAuthFilter.js"></script>
<script type="text/javascript" src="${ctx}/js/modules/code/MessageBox.js"></script>
<style type="text/css">

#upload .title textarea {
	width: 92%;
	height: 90px;
	padding: 5px;
	border: 1px solid #f2f2f2;
}

#upload .option {
	padding-left: 10px;
}

#upload .option input[type='text'] {
	width: 90%;
	height: 24px;
	line-height: 24px;
	padding: 5px;
	border-left: 0px;
	border-right: 0px;
	border-top: 0px;
	border-bottom: 1px solid #f2f2f2;
}

#addNew {
	width: 100px;
	height: 26px;
	font-size: 14px;
}

#upload .no {
	vertical-align: top;
	margin: 0px;
	padding: 0px;
}

#upload .help {
	display: block;
	background: #f2f2f2;
	border: 1px solid #f2f2f3;
}

#upload .analysis {
	width: 100%;
	height: 80px;
	padding: 2px;
	border: 1px solid #f2f2f2;
}
#templete{
	display: none;
}
</style>
 <script type="text/javascript">
	function update(id){
		$(id).slideUp();
	}
	
	function rightAnswer(ques, zhis, langu) {
		zhis.value = zhis.checked;
		var checkbox = $("#" + ques + " ." + langu + " :checkbox[title='"+ zhis.title + "']");
		checkbox.each(function() {
			this.checked = zhis.checked;
			this.value = zhis.checked;
		});
		var answ = undefined;
		$("#" + ques + " ." + langu + " :checked").each(function() {
			if (answ == undefined) {
				answ = "";
			} else {
				answ = answ + ",";
			}
			answ = answ + this.title;
		});
		var hiput = $("#answer" + ques).val(answ);
		 
	}
	function addQuestion(fid,but){
		$.MessageBox.info("提交试题中",-1);
		var form = $(fid);
		$.ajax({
            cache: true,
            type: "POST",
            url:form.attr("action"),
            data:form.serialize(),
            async: false,
            error: function(request) {
           		$(but).show();
            	$.MessageBox.info("网络连接异常");
            },
            success: function(data) {
               if(data){
            	   var pass = $.AjaxAuthFilter.checkSession("${ctx}/user/ajaxLogin.action",data,function(user){
            			updateUser(user);
            		   	addQuestion(fid);
   					});
            	   
	           	   if(pass){
	           	       $.MessageBox.info("操作成功");
	            	   form.remove();
	            	   if($("#context .question").size()<1){
	            		   addNewQuestion();
	            	   }
	           	   }
              }
            }
        });
		
	}
	
	function removeQuestion(fid){
		var form = $(fid);
		 form.remove();
	}
	var allnum = "${fn:length(questions)}";
	function addNewQuestion(){
		var temp = $("#templete");
		var curnum= (++allnum);
		var html = temp.html().replace(/X0X/gi,curnum-1).replace(/X1X/gi,curnum);
	 	$("#context").append(html);
	}
	$(function(){
		if(allnum==0){
			addNewQuestion();
		}
	});
</script>
</head>

<body>
<%@include file="top.jsp"%>


<div id="sidebar" >
	<div class="back"></div>
	<div class="front">
		<div class="center ">
				<table border="0">
					<tr><td class="title"><div style="width: 150px;" class="ellipsis">${paper.title}</div></td>
					 <td class="score">	</td>
					<td class="chlang">
					 <label>中文<input class="language" type="checkbox" onclick="switchLanguage('chinese',this)" checked="checked"></label> 
					 <label>英文<input class="language" type="checkbox" onclick="switchLanguage('english',this)" checked="checked"></label>
					 <label style="margin-left: 10px;">	<a onclick="addNewQuestion()">添加新题</a></label>
					 </td>
					</tr>
				
				</table>
		</div>
	</div>
 </div>

 
 <div id="upload" class="width center radius paper" >
		<div class="examname">
			<h1>${paper.title }</h1>
		</div>
		<div id="context" class="context">			
			<c:forEach var="question" varStatus="tem" items="${questions}">
				<form action="${ctx}/exam/addQuestion.action"   id="form${tem.index}" method="post">
				<input type="hidden"  name="question.paper.id" value="${paper.id }"/>
				<input type="hidden"  name="question.ptype" value="${paper.type }"/>
				<input type="hidden"  name="question.id" value="${question.id }"/>
				<input type="hidden"  name="question.no" value="${question.no }"/>
				<div class="question" id="${tem.index+1}">
				<label>[ 试题编号：${question.no }&nbsp;&nbsp;&nbsp;&nbsp;章节：<z:dic code="${question.chapter }"/> ]</label>
					<ul>
						<li class="english">
							<dt class="title">
								<span class="no">${tem.index+1}.</span> 
								<textarea name="question.enSummary"><c:out value="${question.enSummary }"/></textarea>
							</dt> 
							<c:forEach var="opt" varStatus="otem" items="${question.options }">
								<dd class="option">	 							 
										<input type="checkbox" title="${opt.no}" 
										onclick="rightAnswer('${tem.index+1}',this,'chinese')"
										<c:if test="${ opt.correct }">checked="checked"</c:if> />						 
										<span>${opt.no}.&nbsp;</span>
										<input type="text" name="question.options[${otem.index}].enSummary" value="<c:out value='${opt.enSummary }'/>"/>
								</dd>
							</c:forEach>
						</li>
						<li class="chinese">
							<dt class="title">
								<span class="no">${tem.index+1}.</span>
								<textarea name="question.cnSummary"><c:out value="${question.cnSummary }"/></textarea>
							</dt> 
							<c:forEach var="opt" varStatus="otem" items="${question.options }">
								<dd class="option">
									<input 
									type="checkbox" 
									title="${opt.no}" 
									name="question.options[${otem.index}].correct" 
									value="${opt.correct}" 
									<c:if test="${ opt.correct }">checked="checked"</c:if> 
									onclick="rightAnswer('${tem.index+1}',this,'english');"/>									
									<span>${opt.no }.&nbsp;</span>
									<input type="hidden" name="question.options[${otem.index}].id" value="<c:out value='${opt.id }'/>"/>
 									<input type="hidden" name="question.options[${otem.index}].no" value="<c:out value='${opt.no }'/>"/>
									<input type="text" name="question.options[${otem.index}].cnSummary" value="<c:out value='${opt.cnSummary }'/>"/>
								</dd>
							</c:forEach>
						</li>
					</ul>
					<div align="right">
						<div class="help radius" align="left">
							<div class="left">
								<label>答案：<input type="text" id="answer${tem.index+1}" name="question.answer" value="${question.answer }" style="width: 80px;text-align: center;" readonly="readonly"/></label> 
							</div>
							<div  class="right">
							 <label>章节：
								 <select name="question.chapter" style="width: 200px;">
									 <z:dic code="${paper.type}" isType="true"/>
								 </select>
							 </label>
							  
							</div>
							<div class="clear">
								<textarea name="question.analysis" class="analysis" >${question.analysis }</textarea>
							</div>
						</div>
						<input class="button gray small" type="button" value="移除"  onclick="removeQuestion('#form${tem.index}')"/>
						<input class="button green small" type="button" value="修正"  onclick="addQuestion('#form${tem.index}',this)" />
					</div>
				</div>
				</form>
			</c:forEach>
	</div>
	
	<div id="templete" >
	<form action="${ctx}/exam/addQuestion.action"   id="formX0X" >
		<input type="hidden"  name="question.paper.id" value="${paper.id }"/>
		<input type="hidden"  name="question.ptype" value="${paper.type }"/>
		<div class="question " id="X1X">
			<ul>
				<li class="english">
					<dt class="title">
						<span class="no">X1X.</span> 
						<textarea name="question.enSummary"></textarea>
					</dt> 
					<c:forEach var="opt" varStatus="otem" items="A,B,C,D">
					<dd class="option">	 							 
							<input type="checkbox" title="${opt}" onclick="rightAnswer('X1X',this,'chinese')"/>
							<span>${opt}.&nbsp;</span>
							<input type="text" name="question.options[${otem.index}].enSummary" />
					</dd>
					</c:forEach>
				</li>
				<li class="chinese">
					<dt class="title">
						<span class="no">X1X.</span>
						<textarea name="question.cnSummary"></textarea>
					</dt> 
					<c:forEach var="opt" varStatus="otem" items="A,B,C,D">
						<dd class="option">
							<input 
							type="checkbox" 
							title="${opt}" 
							name="question.options[${otem.index}].correct" 
							onclick="rightAnswer('X1X',this,'english');"/>									
							
							<span>${opt }.&nbsp;</span>
							<input type="hidden" name="question.options[${otem.index}].no" value="<c:out value='${opt }'/>"/>
							<input type="text" name="question.options[${otem.index}].cnSummary" />
						</dd>
					</c:forEach>
				</li>
			</ul>
			<div align="right">
				<div class="help radius" align="left">
					<div class="left">
						<label>答案：<input type="text" id="answerX1X" name="question.answer"   style="width: 80px;text-align: center;" readonly="readonly"/></label> 
					</div>
					<div  class="right">
		
					 <label>章节：
					 <select name="question.chapter" style="width: 200px;">
						 <z:dic code="${paper.type}" isType="true"/>
					 </select></label>
					  
					</div>
					<div class="clear">
						<textarea name="question.analysis" class="analysis" ></textarea>
					</div>
				</div>
				<input class="button gray small" type="button" value="移除"  onclick="removeQuestion('#formX0X')"/>
				<input class="button green small" type="button" value="修正"  onclick="addQuestion('#formX0X',this)"/>
			</div>
		</div>
	</form>
</div>
	</div>	
	
	
<%@include file="../core/bottom.jsp"%>
</body>
</html>
